package com.medicine.hbp.adapter.self;

import org.kymjs.kjframe.KJBitmap;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.medicine.hbp.base.MyBaseAdapter;
import com.medicine.hbp.mob.artGroupVo;
import com.medicine.hbp.ui.WebActivity;
import com.medicine.hbp.R;

public class FragmentUserAdapter01 extends MyBaseAdapter {
	private LayoutInflater inflater;
	private KJBitmap bitmap=new KJBitmap();

	public FragmentUserAdapter01(Activity activity) {
		this.activity=activity;
		inflater = LayoutInflater.from(activity);
	}

	@Override
	public View getView(int position, View view, ViewGroup arg2) {
		viewHolder holder = null;
		if (view == null) {
			holder = new viewHolder();
			view = inflater.inflate(R.layout.item_fragment01, arg2,false);
			holder.text_b_title = (TextView) view.findViewById(R.id.text_b_title);
			holder.text_b_time = (TextView) view.findViewById(R.id.text_b_time);
			holder.text_b_num = (TextView) view.findViewById(R.id.text_b_num);
			holder.img_bq = (ImageView) view.findViewById(R.id.img_bq);
			view.setTag(holder);
		} else {
			holder = (viewHolder) view.getTag();
		}
		final artGroupVo Vo = (artGroupVo) getItem(position);
		if (Vo != null) {
			holder.text_b_title.setText(Vo.artTitle);
			holder.text_b_time.setText(Vo.artDate);
			holder.text_b_num.setText(String.valueOf(Vo.artViewNumber));

			if(TextUtils.isEmpty(Vo.artImg)){
				bitmap.display(	holder.img_bq, Vo.artImg);
			}else{
				holder.img_bq.setImageResource(R.mipmap.imgceshi2);
			}
//			if(Vo.artImg.size()>0){
//				bitmap.display(	holder.img_bq, Vo.artImg.get(0).artImgUrl);
//			}
			view.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					Intent intent = new Intent(activity, WebActivity.class);
					intent.putExtra("isCollect", Vo.isCollect);
					intent.putExtra("ID", Vo.artId);
					intent.putExtra("vo", Vo);
					intent.putExtra("NAME", "文章内容详情");
					intent.putExtra("isCollect", Vo.isCollect);
					activity.startActivity(intent);
				}
			});
		}
		return view;
	}

	class viewHolder {
		TextView text_b_title;// 标题
		TextView text_b_time;// 时间
		TextView text_b_num;// 数量
		ImageView img_bq;//图片
	}

}
